package cn.cvs.controller;

import cn.cvs.pojo.SysUser;
import cn.cvs.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpSession;

@Controller
public class LoginController {

    @Autowired
    private SysUserService sysUserService;

    @GetMapping("/login")
    public String login(){
        return "login";
    }

    @GetMapping("/login2")
    public String login2(){
        return "redirect:/Pear-Admin-Layui/index.jsp";
    }

    @PostMapping("/login")
    public String toLogin(HttpSession session, Model model, String loginName, String password){
        SysUser sysUser = sysUserService.login(loginName, password);

        if (sysUser != null){
            return "redirect:/Pear-Admin-Layui/index.jsp";
        }

        return "login";
    }

}
